package Filter;

import logging.Record;
import logging.Level;
import Exception.InvalidLevelException;

public class LevelFilter implements FilterStrategy{
        
        private Level levelFilter;

        
        public LevelFilter(Level level) {
                this.levelFilter = level;
        
        }
        
        public LevelFilter(String level) {              
        	 
            try{
                    this.levelFilter =  Level.stringToLevel(level);
            }catch (InvalidLevelException e) {
            		e.printStackTrace();
            }       
        } 
        

/*
 * @pre: el mensaje y el filtro deben tenes un nivel
 * 
 * true si el nivel del mensaje es menor al nivel del filtro
 */
        public boolean apply(Record record) {
                        return (this.getLevel().getPriority() >= record.getLevel().getPriority());
        }

        
        public Level getLevel() {
                return this.levelFilter;
        }
        
}
